{% extends "../layout/layout.html" %}

{% block main %}
    <div class="container">
        <div class="row">
            <form class="form-inline">
                <div class="form-group">
                  <label for="version">version</label>
                  <input type="text" class="form-control" id="version" placeholder="请输入版本">
                </div>
                <!-- <button type="submit" class="btn btn-default">搜索</button> -->
                <a href="add" class="btn btn-primary">新增</a>
              </form>
        </div>
        <div class="row">
            <table class="table table-hover">
                <caption>
                    <col>
                    <col width="200">
                    <col width="200">
                    <col>
                </caption>
                <thead>
                    <tr>
                        <th>#</th>
                        <th>版本号</th>
                        <!-- <th>windows</th>
                        <th>macos</th> -->
                        <!-- <th>资源包</th> -->
                        <th>上传时间</th>
                        <th>信息</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                        {% for item in list %}
                            <tr>
                                <td>{{loop.index}}</td>
                                <td>{{item.version}}</td>
                                <td>{{item.create_time}}</td>
                                <td>{{item.remark}}</td>
                                <td>
                                    <button" type="submit" data-id="{{item.id}}" class="public_btn btn btn-success"
                                        {% if item.public %}
                                        disabled
                                        {% endif %}
                                    >发布</button>
                                </td>
                            </tr>
                        {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    <script>
        ~(function(){
            $(document).ready(function(){
                $('.public_btn').bind('click', function(e){
                    var btn = e.target;
                    var id = btn.dataset.id;
                    var confirm = window.confirm('是否确认发布改版本');
                    if (confirm) {
                        $.ajax({
                            method: 'get',
                            url: `api/version/public?id=${id}`
                        }).then(function(res){
                            window.location.reload()
                        }, function(err) {
                            console.error(err);
                            alert('操作出错')
                        });
                    }
                })
            });
        })();
    </script>
{% endblock %}